package com.ymatou.app.api.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.api.parameter.GetAddressByIdBean;
import com.ymatou.app.api.service.GetAddressByIdCall;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.business.service.YmtCallService;
import com.ymttest.utils.constant.ECode;

/**
 * 根据ID获取单个收货地址 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetAddressById {
	private static GetAddressByIdBean getaddbyidbean;
	private static GetAddressByIdCall getaddbyidcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据ID获取单个收货地址");
	}

	@Before
	public void caseUp() {
		getaddbyidbean = new GetAddressByIdBean();
		getaddbyidcall = new GetAddressByIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getaddbyidcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetAddressById_001() {
		Logger.start(true,"根据ID获取单个收货地址成功");
		try {

			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			// 添加一个地址
			YmtCallService ymt = new YmtCallService();
			ymt.addAddress(AccessToken, UserId);
			List AddressIdList = ymt.getAddressId(AccessToken, UserId);
			Integer AddressId = (Integer) AddressIdList.get(0);
			// 设置参数
			getaddbyidbean.setAccessToken(AccessToken);
			getaddbyidbean.setUserId(UserId);
			getaddbyidbean.setAddressId(AddressId);
			// 发送数据
			getaddbyidcall.setData(getaddbyidbean);
			getaddbyidcall.callService();
			Logger.comment("getaddbyidcall send:" + getaddbyidcall.getEntityString());
			Logger.comment("getaddbyidcall response:" + getaddbyidcall.getReturnData());
			Logger.verifyEquals(ECode.APP_MSG3, getaddbyidcall.getMsg(), "验证消息");
			Logger.verifyEquals(ECode.SUCCESS, getaddbyidcall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.BCODE0, getaddbyidcall.getBCode(), "验证BCode");
			Logger.verifyEquals(true, getaddbyidcall.getAddress().length() > 0, "验证查询结果长度");
			Logger.verifyNotNull(getaddbyidcall.getAddressId(), "验证AddressId");
			Logger.verifyEquals(UserId, getaddbyidcall.getUserId(), "验证UserId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}